package com.woniuxy.sddfp.system.controller;

import com.woniuxy.sddfp.common.model.dto.user.LoginDto;
import com.woniuxy.sddfp.common.model.dto.user.UserRegisterDto;
import com.woniuxy.sddfp.common.model.vo.user.LoginVo;
import com.woniuxy.sddfp.common.result.Result;
import com.woniuxy.sddfp.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author yellow doctor
 * @since 2025-05-06
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     *  @Valid  这个注解就是参数校验
     * 用户注册
     */
    @PostMapping("/regist")
    public Result regist(@RequestBody @Valid UserRegisterDto userRegisterDto){

        userService.register(userRegisterDto);

        return Result.ok();
    }

    /**
     * 登录操作
     * @param loginDto
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginDto loginDto){

        //登录  入参  loginDto
        //登录  出参  LoginVo
        LoginVo loginVo = userService.login(loginDto);

        return Result.ok(loginVo);
    }

}
